package app.caihan.wanandroid.ui.find

import android.os.Bundle
import androidx.viewpager2.adapter.FragmentStateAdapter
import app.caihan.scframe.databind.DataBindingConfig
import app.caihan.scframe.util.StatusBarConfig
import app.caihan.wanandroid.BR
import app.caihan.wanandroid.R
import app.caihan.wanandroid.base.WanBaseFragment
import app.caihan.wanandroid.databinding.FragmentFindKnowledgeBinding
import com.google.android.material.tabs.TabLayoutMediator

/**
 *
 *
 * @author Seven-C
 * @date 2020/10/17
 */
class FindKnowledgeFragment : WanBaseFragment<FindKnowledgeFragmentModel>(){

    private val mFindTabLayout by lazy { (getBinding() as FragmentFindKnowledgeBinding).findTabLayout }
    private val mFindViewPager by lazy { (getBinding() as FragmentFindKnowledgeBinding).findViewPager }
    private val mFindTagList by lazy { arrayListOf("体系", "导航") }

    companion object {
        fun newInstance(): FindKnowledgeFragment {
            return FindKnowledgeFragment()
        }
    }

    override fun bindLayoutId(): Int {
        return R.layout.fragment_find_knowledge
    }

    override fun getDataBindingConfig(): DataBindingConfig {
        return DataBindingConfig(BR.vm)
    }

    override fun getStatusBarConfig(): StatusBarConfig? {
        return StatusBarConfig(false,R.color.colorMain)
    }

    override fun initView(savedInstanceState: Bundle?) {
    }

    override fun createObserver() {
    }

    override fun lazyLoadData() {
        mFindViewPager.adapter =
            object : FragmentStateAdapter(this) {

                override fun getItemCount() = mFindTagList.size

                override fun createFragment(position: Int) =
                    KnowledgeListFragment.newInstance(position)

            }
        TabLayoutMediator(mFindTabLayout, mFindViewPager) { tab, position ->
            tab.text = mFindTagList[position]
        }.attach()
    }
}